<?php
	/* var_dump($_FILES);
	echo '<br/>';
	var_dump($_POST); */
	
	//文件上传
	//判断错误号
	$error = $_FILES['logo']['error'];
	switch($error){
		case 1:
		case 2:
			exit('文件过大系统不支持');
		break;
		case 4:
			exit('请选择一个文件');
		break;
		case 3:
		case 6:
		case 7:
			exit('系统内部有误');
		break;
	}
	//允许的mime类型
	$mimeArray = array('image/jpg','image/jpeg','image/png','image/gif');
	//判断mime类型
	$mime = $_FILES['logo']['type'];
	if(!in_array($mime,$mimeArray)){
		exit('文件类型不符');
	}
	//判断文件后缀名
	$fileInfo = pathinfo($_FILES['logo']['name']);
	//拿取后缀名
	$info = $fileInfo['extension'];
	//允许的后缀名
	$infoArray = array('jpg','jpeg','png','gif');
	if(!in_array($info,$infoArray)){
		exit('文件后缀名不符');
	}
	//控制文件大小
	$nowSize = $_FILES['logo']['size'];
	if($nowSize > 2000000){
		exit('文件过大');
	}
	//判断临时文件是否通过post方法生成
	if(is_uploaded_file($_FILES['logo']['tmp_name'])){
		move_uploaded_file($_FILES['logo']['tmp_name'],'./'.$_FILES['logo']['name']);
	}
	//拿取出 值
	$title = $_POST['title'];
	$url = $_POST['url'];
	$logo = $_FILES['logo']['name'];
	$description = $_POST['description'];
	$id = $_POST['id'];
	
	//链接数据库
	$con = mysqli_connect('localhost','root','www');
	mysqli_set_charset($con,'utf8');
	mysqli_select_db($con,'admin');
	$SQL = "update friend set title='{$title}',url='{$url}',logo='{$logo}',description='{$description}' where id={$id}" ;
	mysqli_query($con,$SQL);
	
	if(mysqli_affected_rows($con) >= 1){
		header('location:./friendLink1.php');
	}else{
		header('location:./updateFriend.php');
	}
	
	//关闭
	mysqli_close($con);

?>